package com.example.templateapp.ui.animationtest

import android.os.Bundle
import android.view.animation.Animation
import android.view.animation.LinearInterpolator
import android.view.animation.RotateAnimation
import com.example.templateapp.R
import com.example.templateapp.databinding.ActivityAnimationTestBinding
import com.example.templateapp.ui.base.BaseAppCompatActivity
import com.xuexiang.xutil.display.DensityUtils

class AnimationTestActivity : BaseAppCompatActivity() {

    private val binding: ActivityAnimationTestBinding by binding(R.layout.activity_animation_test)

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        binding.layout.setBackgroundColor(getColor(R.color.colorPrimary))



        binding.v.startAnimation(
            rotateAnimation(
                DensityUtils.dip2px(75f).toFloat(),
                DensityUtils.dip2px(15f).toFloat()
            )
        )

        binding.v1.startAnimation(
            rotateAnimation(
                DensityUtils.dip2px(115f).toFloat(),
                DensityUtils.dip2px(15f).toFloat()
                , 10000
            )
        )

    }

    private fun rotateAnimation(
        pivotX: Float,
        pivotY: Float,
        duration: Long = 10000
    ): RotateAnimation {
        val rotateAnim = RotateAnimation(0f, 360f, pivotX, pivotY)
        rotateAnim.duration = duration
        rotateAnim.interpolator = LinearInterpolator()

        rotateAnim.repeatMode = Animation.INFINITE
        rotateAnim.repeatCount = Animation.INFINITE
        return rotateAnim
    }
}